import subprocess
import IPy
ips = IPy.IP('192.168.0.0/24')
for ip in ips:
    # subprocess.call返回命令的结果和执行状态
    result = subprocess.call(f"ping -c 1 {ip}", shell=True, stdout=subprocess.PIPE)
    if result == 0:
        out = f"{ip}已经被使用了" + "\n"
    else:
        out = f"{ip}没有被使用" + "\n"
    with open("scan_ip.txt", "a", encoding="utf-8") as fe:
        fe.write(out)
